package com.simen.kotlin.demogit;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.ContentFrameLayout;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.KeyboardUtils;
import com.simen.kotlin.view.IOSSwitchView;


public class MainActivity extends AppCompatActivity {


    private View mPaddingView;

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        @SuppressLint("RestrictedApi") final ContentFrameLayout container = new ContentFrameLayout(this);

        LinearLayoutCompat linearLayout = new LinearLayoutCompat(this);
        linearLayout.setOrientation(LinearLayoutCompat.VERTICAL);
        linearLayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        mPaddingView = new View(this);
        LinearLayoutCompat.LayoutParams params = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight());
        mPaddingView.setLayoutParams(params);
        container.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        container.setId(R.id.container);
        linearLayout.addView(mPaddingView);
        linearLayout.addView(container);
//        setContentView(linearLayout);
        setContentView(R.layout.activity_main);

        final AppCompatEditText appCompatEditText = (AppCompatEditText) findViewById(R.id.title_keyword);

        appCompatEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    KeyboardUtils.hideSoftInput(MainActivity.this);
                    Toast.makeText(MainActivity.this, "haah", Toast.LENGTH_SHORT).show();
                    return true;
                }
                return false;
            }
        });

        int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, this.getResources().getDisplayMetrics());

        FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(value, value);

        params.gravity = Gravity.CENTER;


        IOSSwitchView iosSwitchView = (IOSSwitchView) findViewById(R.id.switch_view);

        iosSwitchView.setOn(true);

    }

    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height",
                "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    public void addHandleDemo(View view) {
        startActivity(new Intent(this, HandlerThreadActivity.class));
        finish();
    }

    public void testCopy(View view) {
        startActivity(new Intent(this, ClipBoardActivity.class));
        finish();
    }
}
